package com.niit.onlinemusic.controller;

import com.niit.onlinemusic.common.R;
import com.niit.onlinemusic.model.request.RankListRequest;
import com.niit.onlinemusic.service.RankListService;
import org.springframework.web.bind.annotation.*;

/**
 * 歌单评分控制器
 *
 * @author zuwei522
 * @since 2025/9/29 22:39
 */
@RestController
public class RankListController {

    private final RankListService rankListService;

    public RankListController(RankListService rankListService) {
        this.rankListService = rankListService;
    }

    /**
     * 获取用户对某个歌单的评分
     *
     * @param consumerId 用户id
     * @param songListId 歌单id
     * @return R
     * @author zuwei522
     * @since 2025/9/29 22:48
     */
    @GetMapping("rankList/user")
    public R getUserRank(@RequestParam("consumerId") Long consumerId, @RequestParam("songListId") Long songListId) {
        return rankListService.getUserRank(consumerId, songListId);
    }

    /**
     * 提交评分
     *
     * @param rankListAddRequest 评分请求体
     * @return R
     * @author zuwei522
     * @since 2025/9/29 23:14
     */
    @PostMapping("rankList/add")
    public R addRank(@RequestBody RankListRequest rankListAddRequest) {
        return rankListService.addRank(rankListAddRequest);
    }

    /**
     * 获取指定歌单的评分（平均分）
     *
     * @param songListId 歌单id
     * @return R
     * @author zuwei522
     * @since 2025/9/29 23:17
     */
    @GetMapping("rankList")
    public R rankOfSongListId(@RequestParam Long songListId) {
        return rankListService.rankOfSongListId(songListId);
    }

}
